package com.serkol.ams.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.serkol.ams.bean.MyPageOld;
import com.serkol.ams.entity.VideoDetail;
import com.serkol.ams.mapper.VideoDetailMapper;
import com.serkol.ams.modal.SqlFeildModal;
import com.serkol.ams.service.VideoDetailService;
import com.serkol.handler.MyLambdaQueryWrapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author pingan
 * @description 针对表【video_detail】的数据库操作Service实现
 * @createDate 2023-10-31 19:38:54
 */
@Service
public class VideoDetailServiceImpl extends ServiceImpl<VideoDetailMapper, VideoDetail>
        implements VideoDetailService {

    @Override
    public MyPageOld findByList(int pageSize, int page1, long masterId) {

        MyLambdaQueryWrapper<VideoDetail> queryWrapper = new MyLambdaQueryWrapper<>();
        queryWrapper.select(VideoDetail::getId, VideoDetail::getRate, VideoDetail::getName, VideoDetail::getContent, VideoDetail::getContent);
        queryWrapper.select(VideoDetail::getContentUg).as("contentUg")
                .select(VideoDetail::getViewCount).as("viewCount")
                .select(VideoDetail::getCreateDate).as("createDate")
                .select(VideoDetail::getUrl).as("url")
                .select(VideoDetail::getMasterId).as("masterId")
                .select(VideoDetail::getLikeCount).as("likeCount");


        queryWrapper.orderByAsc(VideoDetail::getName).eq(VideoDetail::getMasterId, masterId);
        Page<Map<String, Object>> page = new Page<>(page1, pageSize);
        Page<Map<String, Object>> mapPage = this.baseMapper.selectMapsPage(page, queryWrapper);
        return MyPageOld.parsePage(mapPage);
    }

    @Override
    public List<Map<String, Object>> findByList(long masterId) {
        MyLambdaQueryWrapper<VideoDetail> queryWrapper = new MyLambdaQueryWrapper<>();
        queryWrapper.select(VideoDetail::getId, VideoDetail::getRate, VideoDetail::getName, VideoDetail::getContent, VideoDetail::getContent);
        queryWrapper.select(VideoDetail::getContentUg).as("contentUg")
                .select(VideoDetail::getViewCount).as("viewCount")
                .select(VideoDetail::getCreateDate).as("createDate")
                .select(VideoDetail::getUrl).as("url")
                .select(VideoDetail::getMasterId).as("masterId")
                .select(VideoDetail::getLikeCount).as("likeCount");


        queryWrapper.orderByAsc(VideoDetail::getName).eq(VideoDetail::getMasterId, masterId);
        return listMaps(queryWrapper);
    }

    @Override
    public MyPageOld findByPlayList(int pageSize, int page1) {

        MyLambdaQueryWrapper<VideoDetail> queryWrapper = new MyLambdaQueryWrapper<>();
        queryWrapper.select(VideoDetail::getId, VideoDetail::getRate, VideoDetail::getName);
        queryWrapper.langName(VideoDetail::getContent,VideoDetail::getContentUg).as("content")
                .select(VideoDetail::getViewCount).as("viewCount")
                .select(VideoDetail::getCreateDate).as("createDate")
                .select(VideoDetail::getUrl).as("url")
                .select(SqlFeildModal.getPictureKey("(SELECT  IMAGE_ID FROM video_master as tvideo_master WHERE  ID=MASTER_ID   LIMIT 1)")).as("poster")
                .select("(SELECT  GOODS_ID FROM video_master as tvideo_master WHERE  ID=MASTER_ID   LIMIT 1)").as("goodsId")
                .select("IFNULL((SELECT  ID FROM video_likes WHERE  MASTER_ID=x.MASTER_ID AND DETAIL_ID=x.ID  LIMIT 1),0)").as("zan")
                .select("(SELECT  (SELECT  NAME FROM goods WHERE  ID=GOODS_ID   LIMIT 1) FROM video_master as tvideo_master  WHERE  ID=MASTER_ID  LIMIT 1)").as("goodsName")
                .langNameSql("(SELECT  NAME FROM video_master as tvideo_master WHERE  ID=MASTER_ID   LIMIT 1)","(SELECT  NAME_UG FROM video_master as tvideo_master WHERE  ID=MASTER_ID   LIMIT 1)").as("masterName")
                .select(VideoDetail::getMasterId).as("masterId")
                .select(VideoDetail::getLikeCount).as("likeCount");


        queryWrapper.orderByDesc(VideoDetail::getRate, VideoDetail::getId, VideoDetail::getViewCount);
        Page<Map<String, Object>> page = new Page<>(page1, pageSize);
        Page<Map<String, Object>> mapPage = this.baseMapper.selectMapsPage(page, queryWrapper);
        return MyPageOld.parsePage(mapPage);
    }
}




